import Mock from 'mockjs';

// 生成列表数据
Mock.mock(/\/api\/v1\/phase-summary\/list/, 'get', (options: { url: string }) => {
  const params = new URLSearchParams(options.url.split('?')[1]);
  const page = parseInt(params.get('page') || '1');
  const pageSize = parseInt(params.get('pageSize') || '20');

  return {
    code: 200,
    data: {
      total: 100,
      list: Mock.mock({
        [`list|${pageSize}`]: [{
          'summaryId|+1': Mock.Random.guid(),
          'title': '@ctitle(5, 20)',
          'phase': {
            'start': '@date',
            'end': '@date'
          },
          'status|1': ['draft', 'published'],
          'author': '@cname',
          'createTime': '@datetime',
          'updateTime': '@datetime',
          'tags|1-3': ['@ctitle(2, 4)']
        }]
      }).list
    },
    message: 'success'
  };
});

// 生成详情数据
Mock.mock(/\/api\/v1\/phase-summary\/[\w-]+$/, 'get', () => {
  return {
    code: 200,
    data: Mock.mock({
      'summaryId': '@guid',
      'title': '@ctitle(5, 20)',
      'phase': {
        'start': '@date',
        'end': '@date'
      },
      'content': {
        'overview': '@cparagraph(3, 7)',
        'achievements|2-5': [{
          'title': '@ctitle(5, 10)',
          'description': '@cparagraph(1, 3)',
          'metrics|2-4': [{
            'name': '@ctitle(2, 4)',
            'value|1-1000': 1,
            'unit|1': ['个', '次', '%', '元']
          }]
        }],
        'problems|1-3': [{
          'title': '@ctitle(5, 10)',
          'description': '@cparagraph(1, 2)',
          'solution': '@cparagraph(1, 2)'
        }],
        'nextPlan': '@cparagraph(2, 4)'
      },
      'attachments|0-3': [{
        'fileId': '@guid',
        'fileName': '@ctitle(5, 10).@pick(["doc","pdf","xlsx"])',
        'fileSize|1-10000': 1,
        'fileType|1': ['document', 'spreadsheet', 'pdf']
      }],
      'relatedReports|0-2': [{
        'reportId': '@guid',
        'title': '@ctitle(5, 15)',
        'type|1': ['weekly', 'monthly', 'quarterly']
      }],
      'status|1': ['draft', 'published'],
      'author': '@cname',
      'createTime': '@datetime',
      'updateTime': '@datetime',
      'tags|1-3': ['@ctitle(2, 4)']
    }),
    message: 'success'
  };
});

// 创建总结
Mock.mock('/api/v1/phase-summary', 'post', () => {
  return {
    code: 200,
    data: {
      summaryId: Mock.Random.guid()
    },
    message: '创建成功'
  };
});

// 更新总结
Mock.mock(/\/api\/v1\/phase-summary\/[\w-]+$/, 'put', () => {
  return {
    code: 200,
    message: '更新成功'
  };
});

// 删除总结
Mock.mock(/\/api\/v1\/phase-summary\/[\w-]+$/, 'delete', () => {
  return {
    code: 200,
    message: '删除成功'
  };
});